class Solution {
public:
    int minimumRecolors(string blocks, int k) {
        const int INF=0x3f3f3f3f;
        int n=blocks.size();
        int ret=INF;
        int whiteCnt=0;
        for(int left=0,right=0;right<n;++right)
        {
            if(blocks[right]=='W') ++whiteCnt;
            while(left<right&&right-left+1>k)
            {
                if(blocks[left++]=='W') --whiteCnt;
            }
            if(right-left+1>=k) ret=min(ret,whiteCnt);
        }
        return ret;
    }
};